package com.college.dao;

import java.util.List;

import com.college.entity.Work;

public class WorkDao extends WorkBaseDao<Work> {
	public List<Work> queryToWork(int uid, int state) {
		String hql;
		List<Work> works;
		if (state == 0 && uid == 0) {
			hql = "from Work";
			works = queryEntiy(hql);
		} else if (state == 0) {
			hql = "from Work where uid=?";
			works = queryEntiy(hql, uid);
		} else if (uid == 0) {
			hql = "from Work where state=?";
			works = queryEntiy(hql, state);
		} else {
			hql = "from Work where uid=? and state=?";
			works = queryEntiy(hql, uid, state);
		}
		return works;
	}

	public void save(Work work) {
		super.save(work);
	}
	
	public boolean updatework(Work work) {
		try {
			String hql="update Work set state = '"+work.getState()+"' where wid = '"+work.getWid()+"'";
			super.update(hql);
			return true;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return false;
	}

}
